<template>
	<div>
		<div class="publish-top">
			<div class="left-icon" @click="handleBack"> 
				<img src="../../../assets/images/left.png"/>
			</div>
			<p>设置</p>
		</div>
		<div class="set-content">
			<ul class="set-list">
				<li @click="handleModify">
					<span>修改资料</span>
					<img src="../../../assets/images/message/message-icon.png"/>
				</li>
				<li @click="handleChange">
					<span>更改密码</span>
					<img src="../../../assets/images/message/message-icon.png"/>
				</li>
				<li @click="handAbout">
					<span>关于我们</span>
					<img src="../../../assets/images/message/message-icon.png"/>
				</li>
			</ul>
			<div class="out" @click="handleOut">退出登陆</div>
		</div>
	</div>
</template>

<script>
	
	var auths = null;
	export default{
		data(){
			return{
				isClick:true
			}
		},
		created(){
			let plusReady = ()=>{
				plus.oauth.getServices( function(services){
//					console.log(JSON.stringify(services))
					auths = services;
				}, function(e){
					alert( "获取分享服务列表失败："+e.message+" - "+e.code );
				} );
				
			}
			if (window.plus) {
		      plusReady();
		   } else {
		      document.addEventListener("plusready", plusReady, false);
		   }
		},
		components:{
			
		},
		methods:{
			handleBack(){
				var set = plus.webview.currentWebview();
				plus.webview.close(set);
			},
			handleModify (){
				if(this.isClick){
					this.isClick = false;
					var modify = plus.webview.create('modify.html','modify',{scrollIndicator:'none'},{});
					modify.addEventListener("loaded", ()=> {
					    modify.show('pop-in', 300);
					    this.isClick = true;
					    modify = null;
					}, false);
				}
			},
			handleChange () {
				if(this.isClick){
					this.isClick = false;
					var change = plus.webview.create('change.html','change',{scrollIndicator:'none'},{});
					change.addEventListener("loaded", ()=> {
					    change.show('pop-in', 300);
					    this.isClick = true;
					    change = null;
					}, false);
				}	
			},
			handAbout(){
				if(this.isClick){
					this.isClick = false;
					var about = plus.webview.create('about.html','about',{scrollIndicator:'none'},{});
					about.addEventListener("loaded", ()=> {
					    about.show('pop-in', 300);
					    this.isClick = true;
					    about = null;
					}, false);
				}	
			},
			handleOut(){
				for(var i=0;i<auths.length;i++){
					if(auths[i].authResult==null){
						var home = plus.webview.getWebviewById('home');
						plus.webview.close(home)
						var collect = plus.webview.getWebviewById('collect');
						plus.webview.close(collect)
						var message = plus.webview.getWebviewById('message');
						plus.webview.close(message)
						var mine = plus.webview.getWebviewById('mine');
						plus.webview.close(mine)
						
						
						window.localStorage.removeItem("userInfo");
						plus.nativeUI.showWaiting( "退出登录..." );
						plus.webview.getLaunchWebview().reload();
						setTimeout( function(){
//							plus.webview.getLaunchWebview().show();
						   plus.webview.getWebviewById('home').show();
						   plus.nativeUI.closeWaiting();
						   var set = plus.webview.getWebviewById('set');
						   plus.webview.close(set)
						}, 2000);
					}else{
						break;
					}
				}
				for (var i in auths) {
               var s = auths[i];
               if (s.authResult) {
						var home = plus.webview.getWebviewById('home');
						plus.webview.close(home)
						var collect = plus.webview.getWebviewById('collect');
						plus.webview.close(collect)
						var message = plus.webview.getWebviewById('message');
						plus.webview.close(message)
						var mine = plus.webview.getWebviewById('mine');
						plus.webview.close(mine)
						
	               s.logout(function(e) {
	               	console.log('注销登录认证成功!')
	               	plus.nativeUI.showWaiting( "退出登录..." );
	               	window.localStorage.removeItem("userInfo");
	               	plus.webview.getLaunchWebview().reload();						   
							setTimeout( function(){
							   plus.nativeUI.closeWaiting();
//								plus.webview.getLaunchWebview().show();
						   	plus.webview.getWebviewById('home').show();
						   	var set = plus.webview.getWebviewById('set');
						   	plus.webview.close(set)
							}, 2000 );
	               }, function(e) {
	                  console.log("注销登录认证失败！");
	               });
	            }
            }
			}
		}
	}
</script>

<style lang="less">

	html,body{
		padding: 0;
		margin: 0;
		width: 100%;
		height: 100%;
		background: #f6f6f6;
	}
	*{
		margin: 0;
		padding: 0;
	}
	ul,li{
		list-style: none;
	}
	.publish-top{
		width: 100%;
		height: 60px;
		background:@default-blue;
		box-shadow: 0px 0px 8px 1px #999;
		padding-top: 70px;
		display:flex;				
		.left-icon{
			width: 90px;
			img{
				width: 15px;
				height: 26px;
				margin-left: 31px;
			}
		}
		p{		
			width: 80%;
			color: #fff;
			font-size: 28px;
			text-align: center;
		}
		span{
			display: block;
			width: 170px;
			color: #fff;
			font-size: 28px;
			text-align: center;
		}
	}
	.set-content{
		width: 100%;
		.set-list{
			margin-bottom: 42px;
			padding: 0 24px;
			background: #fff;
			li{
				height: 148px;
				line-height: 148px;
				border-bottom: 0.1rem solid #eeeeee;
				display: flex;
				justify-content: space-between;
				background: #fff;
				span{
					font-size: 28px;
					color: #333;
				}
				img{
					margin-top: 61px;
					display: block;
					width: 16px;
					height: 27px;
				}
			}
			li:last-child{
				border-bottom: none;
			}
		}
		.out{
			width: 100%;
			height: 178px;
			line-height: 178px;
			font-size: 28px;
			color: #333;
			text-align: center;
			background: #fff;
			background: #FFFFFF;
		}
	}
</style>